package com.youyi.yyfilepickerlibrary.core;

import android.app.Activity;
import android.support.v4.app.Fragment;
import java.lang.ref.WeakReference;

public final class FilePicker {
    private final WeakReference<Activity> mContext;
    private final WeakReference<Fragment> mFragment;

    private FilePicker(Activity activity) {
        this(activity, null);
    }

    private FilePicker(Fragment fragment) {
        this(fragment.getActivity(), fragment);
    }

    private FilePicker(Activity activity, Fragment fragment) {
        this.mContext = new WeakReference<>(activity);
        this.mFragment = new WeakReference<>(fragment);
    }

    public static FilePicker from(Activity activity) {
        return new FilePicker(activity);
    }

    public static FilePicker from(Fragment fragment) {
        return new FilePicker(fragment);
    }

    public SelectCreator chooseForBrowser() {
        return new SelectCreator(this, SelectOptions.CHOOSE_TYPE_BROWSER);
    }

    public SelectCreator chooseForMimeType() {
        return new SelectCreator(this, SelectOptions.CHOOSE_TYPE_SCAN);
    }

    public SelectCreator chooseMedia() {
        return new SelectCreator(this, SelectOptions.CHOOSE_TYPE_MEDIA);
    }

    public Activity getActivity() {
        return this.mContext.get();
    }

    public Fragment getFragment() {
        WeakReference<Fragment> weakReference = this.mFragment;
        if (weakReference != null) {
            return weakReference.get();
        }
        return null;
    }
}
